package cn.com.bluemoon.daps.api.sys.factory;

import cn.com.bluemoon.daps.api.sys.RemoteSysDeptService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiSystem;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.system.entity.DapSystemDepartment;
import cn.com.bluemoon.daps.system.entity.DapSystemWechatDept;
import cn.com.bluemoon.daps.system.vo.DapSystemWechatDeptTreeVo;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Component
public class RemoteSysDeptServiceFallbackFactory implements FallbackFactory<RemoteSysDeptService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSysDeptServiceFallbackFactory.class);


    @Override
    public RemoteSysDeptService create(Throwable throwable) {
        log.error("系统服务调用失败:{}", throwable.getMessage());
        return new RemoteSysDeptService() {
            @Override
            public ResultBean<DapSystemDepartment> getById(String id) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统部门失败！");
            }

            @Override
            public Map<String, String> dbDistinctDepartAndIdMap() {
                return Collections.emptyMap();
            }

            @Override
            public ResultBean<List<DapSystemDepartment>> listAll() {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统部门失败！");
            }

            @Override
            public ResultBean<DapSystemWechatDept> getWechatDeptById(String id) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统部门失败！");
            }

            @Override
            public ResultBean<List<DapSystemWechatDept>> getWechatDeptByName(String name) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统部门失败！");
            }

            @Override
            public ResultBean<List<DapSystemWechatDeptTreeVo>> getWechatDeptList(Integer level) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统部门失败！");
            }
        };
    }
}
